var timeout = 1;

function sendData()
{
  tfNickText = document.getElementById("tfNick").value;
  tfDaneText = document.getElementById("tfDane").value;
  if(tfNickText == ""){
    alert("Prosz wprowadzi nick.");
    return;
  }
  if(tfDaneText == ""){
    alert("Prosz wprowadzi wypowied.");
    return;
  }
  url = "http://localhost/chat.php?nick=" + tfNickText;
  url += "&dane=" + tfDaneText;
  url = encodeURI(url);
  startGETRequest2(url);
}

function startChat()
{
  startGETRequest1("http://localhost/chat.php?rows=10");
  setTimeout("startChat();", timeout * 1000);
}

function requestEnd()
{
}

function requestCompleted1(text, xml)
{
  var chatDiv = document.getElementById("chatDiv");
  if(text.substr(0, 5) != "error"){
    chatDiv.innerHTML = text;
  }
  else{
    arr = text.split(":");
    if(arr.length != 2){
      chatDiv.innerHTML = "Otrzymano niepoprawne dane.";
    }
    else{
      chatDiv.innerHTML = arr[1];
    }
  }
}

function requestCompleted2(text, xml)
{
  var chatDiv = document.getElementById("chatDiv");
  if(text.substr(0, 5) == "error"){
    arr = text.split(":");
    if(arr.length != 2){
      alert ("Otrzymano niepoprawne dane.");
    }
    else{
      alert(arr[1]);
    }
  }
  else{
    document.getElementById("tfDane").value = "";
  }
}